package a7;
import java.util.Scanner;

public class IntToCheck 
{
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);		//get the number
		System.out.print("Enter an amount: ");
		int x = sc.nextInt();
		String Text = null;
		if(x<1000)					//1-999   through hundreds
		{
			String number=toText(x);
			Text=(number);
		}
		else if(x<1000000)				//1,000-999,999 through thousands
		{ 
			int part1 = x%1000;			// (hundreds)0-999
			int part2 = x/1000;			// (thousands) 1,000-999,000
			String hund = toText(part1);
			String thou= toText(part2);
			Text=(thou + "thousand "+ hund );
		}
		else if(x<1000000000)					//  		through millions
		{
			int part1=x%1000;			//hundreds
			int part2=(x/1000)%1000;	//thousands
			int part3=x/1000000;		//millions
			String hund = toText(part1);
			String thou= toText(part2);
			String mill= toText(part3);
			if(part2==0)
				Text=(mill+ "million " + hund);
			else
				Text=(mill + "million " + thou + "thousand " + hund);
		}
		
//		Text=text.toUpperCase();							//????? How do I make the first letter capitalized?
		System.out.println(Text); 
	}

	static String toText (int n)
	{
		String [] onesarray=new String[] {"" ,"one ","two ","three ","four ","five ","six ","seven ","eight ","nine "};
		String [] tensarray=new String[] {"" ,"ten","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"};
		String [] teensarray=new String[] {"ten ","eleven ","twelve ","thirteen ","fourteen ","fifteen ","sixteen ","seventeen ","eighteen ","nineteen "};
		String hundreds = "";
		for(int i=1;i<10;i++)
			if(n/100==i)
			{
				hundreds=onesarray[i]+"hundred ";
			}
		int tensplace=(n%100)/10;		//(remove 100s place) and get just tens
		String tens = ""; 
		for(int i=2;i<10;i++)
			if(tensplace==i)
				tens=tensarray[i];
		if( n%100<20 && n%100>9)	//for teens
			for(int i=10;i<20;i++)
				if(n%100==i) 
					tens=teensarray[i-10]; 
		String ones="";
		int onesplace=n%10;					//get ones
		if(tensplace>=2||tensplace<1)			//only add ones if not in teens
			for(int i=0;i<10;i++) 
			{
				if( onesplace==i)
					ones= onesarray[i];
			}
		String dash=" ";
		if(tensplace>1 && onesplace!=0 )
			dash="-";
		else if(tensplace<2)
			dash="";
		String finish= (hundreds + tens + dash + ones);
		return finish;
	}
}